package liumengbaio.lolzhangyoubao.Activity.Fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.Adapter.ViewPager_HeroAdapter;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/8/23.
 */
public class FragmentHero extends Fragment{
    private TabLayout tablayout;
    private ViewPager viewpager;
    //tab标签名称值集合
    private List<String> tabNames;
    //Fragment数据集合
    private List<Fragment> fragments;
    //ViewPagerAdapter的适配器
    private ViewPager_HeroAdapter pager_heroAdapter;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
       View view = inflater.inflate(R.layout.fragment_hero,null);
        return view;

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView(getView());
        initData();
    }

    private void initView(View view) {
        tablayout = (TabLayout) view.findViewById(R.id.tab_hero);
        viewpager = (ViewPager) view.findViewById(R.id.vp_hero);
    }
    private void initData() {
        //整理tablayout中的数据
        tabNames =new ArrayList<>();
        tabNames.add("周免/折扣");
        tabNames.add("我的英雄");
        tabNames.add("全部英雄");
        //整理ViewPager的数据集合
        fragments =new ArrayList<>();
        FragmentHeroWeekFreeOrDiscount HeroWeekFreeOrDiscount =new FragmentHeroWeekFreeOrDiscount();
        fragments.add(HeroWeekFreeOrDiscount);
        FragmentHeroMyHeroUnlogin myHero =new FragmentHeroMyHeroUnlogin();
        fragments.add(myHero);
        FragmentHeroAllHero allHero =new FragmentHeroAllHero();
        fragments.add(allHero);
        pager_heroAdapter = new ViewPager_HeroAdapter(getFragmentManager(),tabNames,fragments);
        viewpager.setAdapter(pager_heroAdapter);
        tablayout.setupWithViewPager(viewpager);
    }
}
